<cfsetting enablecfoutputonly="Yes">

<!--- 
  /**
   * The heart and soul of the Mireau application.
   *
   * @author  <info@mireau.net>
   * @version 1.0 - <yyyy/mm/dd>
   */
--->

<cfinclude template="./app_variables.cfm">
<cfinclude template="./app_status.cfm">
<cfinclude template="#request.site.s_CFROOT#/lib/udf/utils.cfm">

<cfsetting enablecfoutputonly="No">

  <cfif fileExists( "#request.site.s_ANCHOR_PATH#/www/#request.site.s_CURRENT_PATH#/app_locals.cfm" )>
    <cfinclude template="#request.site.s_CFROOT#/www/#request.site.s_CURRENT_PATH#/app_locals.cfm">
  </cfif>
  
  <cfset local.bFileIncluded = 0>

  <cfsavecontent variable="request.bodycontent">

    <cfloop from="1" to="#arrayLen( request.fusebox.xFuseaction )#" index="nMireauIndex">

      <cfscript>
        pre                     = request.fusebox.xFuseaction[nMireauIndex][1];
        ext                     = request.fusebox.xFuseaction[nMireauIndex][2];
        dir                     = request.fusebox.xFuseaction[nMireauIndex][3];
        local.bIndexProcessing  = request.fusebox.xFuseaction[nMireauIndex][4];
        local.bCheckForIncludes = request.fusebox.xFuseaction[nMireauIndex][5];
      </cfscript>

      <cfif local.bIndexProcessing>

        <!--- //
              // Exception for JavaScript files. If we can find a JavaScript 
              // file for this fuseaction, we will include it at the top of our
              // page by using a <cfhtmlhead> tag.
              //
        --->
        <cfif ( ext eq "js" )>
          <cfif fileExists( "#request.site.s_ANCHOR_PATH#/www/#request.site.s_CURRENT_PATH#/_#dir#/#pre#_#attributes.fuseaction#.#ext#" )>
            <cfhtmlhead text="#chr( 13 )#    <script type=""text/javascript"" src=""/#listChangeDelims( "#request.site.s_WEBROOT#/#request.site.s_CURRENT_PATH#/_#dir#/#pre#_#attributes.fuseaction#.#ext#", '/', '/' )#""></script>">
          </cfif>

        <!--- //
              // Otherwise (for all other extensions than "js"): include all 
              // files if they are present in the filesystem. The order in which
              // we will process files is like this:
              //
              //    * the current dir (unscoped by directory type)
              //    * the directory type in the current dir
              //    * the system directory (sort of a fallback mechanism)
              //
        --->
        <cfelse>
          <cfif fileExists( "#request.site.s_ANCHOR_PATH#/www/#request.site.s_CURRENT_PATH#/#pre#_#attributes.fuseaction#.#ext#" )>
            <cfinclude template="#request.site.s_CFROOT#/www/#request.site.s_CURRENT_PATH#/#pre#_#attributes.fuseaction#.#ext#">
            <cfscript>if( local.bCheckForIncludes ) { local.bFileIncluded = 1; }</cfscript>
    
          <cfelseif fileExists( "#request.site.s_ANCHOR_PATH#/www/#request.site.s_CURRENT_PATH#/_#dir#/#pre#_#attributes.fuseaction#.#ext#" )>
            <cfinclude template="#request.site.s_CFROOT#/www/#request.site.s_CURRENT_PATH#/_#dir#/#pre#_#attributes.fuseaction#.#ext#">
            <cfscript>if( local.bCheckForIncludes ) { local.bFileIncluded = 1; }</cfscript>
    
          <cfelseif fileExists( "#request.site.s_ANCHOR_PATH#/sys/#dir#/#pre#_#attributes.fuseaction#.#ext#" )>
            <cfinclude template="./#dir#/#pre#_#attributes.fuseaction#.#ext#">
            <cfscript>if( local.bCheckForIncludes ) { local.bFileIncluded = 1; }</cfscript>
          </cfif>
        </cfif>
      </cfif>
    </cfloop>

    <cfif not local.bFileIncluded>
      <cfinclude template="../lib/blocks/dsp_404.cfm">
    </cfif>

  </cfsavecontent><cfif len( request.site.s_HEADERFILE )><cfinclude template="../#request.site.s_HEADERFILE#"></cfif><cfoutput>#trim( request.bodycontent )#</cfoutput><cfif len( request.site.s_FOOTERFILE )><cfinclude template="../#request.site.s_FOOTERFILE#"></cfif>